package com.jiinfo.util;

import java.io.IOException;
import java.io.InputStream;

public class ByteUtil {

	  public static final byte[] readBytes(InputStream is, int contentLen) {
	        if (contentLen > 0) {
	                int readLen = 0;

	                int readLengthThisTime = 0;

	                byte[] message = new byte[contentLen];

	                try {

	                        while (readLen != contentLen) {

	                                readLengthThisTime = is.read(message, readLen, contentLen
	                                                - readLen);

	                                if (readLengthThisTime == -1) {// Should not happen.
	                                        break;
	                                }

	                                readLen += readLengthThisTime;
	                        }

	                        return message;
	                } catch (IOException e) {
	                        // Ignore
	                        // e.printStackTrace();
	                }
	        }
	        return new byte[] {};
	}
	
}
